﻿using System;
using System.Collections.Generic;
using System.Text;
using ECC_EXT_Entity;
using NHibernate;
using NHibernate.Criterion;

namespace ECC_EXT_DAO.Dao
{
    public class MailParagraghContentDao:DaoBase
    {
        public void SaveOrUpdate(MailParagraghContentEntity _paragraghContentEntity)
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                session.BeginTransaction();
                session.SaveOrUpdate(_paragraghContentEntity);
                session.Transaction.Commit();
            }
        }

        public void Delete(MailParagraghContentEntity _entity)
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                session.BeginTransaction();
                session.Delete(_entity);
                session.Transaction.Commit();
            }
        }

        public IList<MailParagraghContentEntity> Search(long pParagraghID)
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                ICriteria criteria =
                    session.CreateCriteria<MailParagraghContentEntity>();
                criteria.Add(Restrictions.Eq("ParagraphID", pParagraghID));
                criteria.AddOrder(Order.Asc("Name"));
                return
                criteria.List<MailParagraghContentEntity>();
            }
        }
    }
}
